<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
	<title>结算</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="format-detection" content="telephone=no" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0,  maximum-scale=1.0" />
		<meta name="format-detection" content="telephone=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<link rel="stylesheet" type="text/css" href="${ctxStatic}/shopcartstatic/css/public.css" />
		<link rel="stylesheet" href="${ctxStatic}/shopcartstatic/css/easyLife/weui.min.css">
		<link rel="stylesheet" href="${ctxStatic}/shopcartstatic/css/easyLife/style.css">
</head>
<body>
<header class="header">
	<div class="h-back" onclick="javascript:history.go(-1)"><span>返回</span></div>
    <c:if test="${stt==1}">
        <div class="h-title">订单详情</div>
    </c:if>
    <c:if test="${stt==0}">
        <div class="h-title">订单结算</div>
    </c:if>
	<div class="h-right"></div>
</header>


<div class="weui-cells default-address">


</div>

<div class="weui-cells order-goods-list">

    <c:forEach items="${order.list}" var="list">

        <div class="weui-cell goods-item1" data-id="1" data-cover="1" data-title="商品1" data-price="1" data-yb="1">
              <div class="weui-cell__hd"><img src="${ctxStatic}/shopcartstatic/images/40.png" alt="" style="width:45px;height:45px;margin-right:15px;display:block"></div>
              <div class="weui-cell__bd">
                <p>${list.product.name}</p>
                <p>${list.productNum}</p>
              </div>
              <div class="weui-cell__ft money">￥${list.productPrice}</div>
        </div>
    </c:forEach>
</div>

<div class="weui-cells">
    <div class="weui-cell">
         <div class="weui-cell__bd">
             <p>总价</p>
         </div>
         <div class="weui-cell__ft j_total_money money">￥${tt}</div>
     </div>
</div>

<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="订单备注">
        </div>
    </div>
</div>

<div class="weui-cells">
    <div class="weui-cell" style="background: #efeff4">
        <div class="weui-cell__bd">
            <c:if test="${stt==0}">
                <a href="orderResult?id=${order.id}" class="weui-btn weui-btn_primary ">微信支付</a>
            </c:if>
            <c:if test="${stt==1}">
                <a  class="weui-btn weui-btn_primary ">已支付</a>
            </c:if>
        </div>
    </div>
</div>

<div class="js_dialog" id="alertDialog" style="display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary j_confirm">知道了</a>
        </div>
    </div>
</div>

<script id="item-template" type="text/html">

</script>

<script src="${ctxStatic}/shopcartstatic/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
var orderid = '${order.id}';

    var home = '${home}';
    var homes = '${homes}';
    console.log("-----"+home)
    console.log("-----"+(homes != null && homes != ''))
    if(homes != null && homes != ''){
        homes = '${homes}';
    }else{
        homes = '';
    }

    $(function () {
        var money = 0;
        var addrId = "1";
        var goodsArr = [];

        init();

        function init() {
            calc();

            // addr
            var addrHtml = "";

            //默认地址
            if (homes != null && homes != '') {
                addrHtml += "<p>姓名:${username}</p >";
                addrHtml += "<p>电话:${tel}</p >";
                addrHtml += "<p>地址:${address}</p >";
            } else {
                if (home == null || home == '[]') {
                    addrHtml = '<a class="weui-cell weui-cell_access" href="addaddress?orderid='+orderid+'">' +
                        '        <div class="weui-cell__bd j_address"><p>请添加收货地址</p ></div>' +
                        '        <div class="weui-cell__ft"></div>' +
                        '    </a >'
                } else {
                    addrHtml = '<a class="weui-cell weui-cell_access" href="order-address?orderid='+orderid+'">' +
                        '        <div class="weui-cell__bd j_address"><p>请选择收货地址</p ></div>' +
                        '        <div class="weui-cell__ft"></div>' +
                        '    </a >'
                }
            }
            $(".default-address").html(addrHtml);

        }

    $(".weui-pay").click(function () {
        var m = "是否确定支付？"
        if (confirm(m) == true) {
            window.location = "order-result";
        } else {

        }
    })

    function calc() {
		var totalMoney = 1, totalYb = 1, totalNum = 1;

		// $(".j_total_money").html("￥"+totalMoney);
		$(".j_total_yb").html(totalYb);
		$(".j_total_num").html(totalNum);
		if (goodsArr.length == 0) {
			$(".j_total_num").hide();
			$(".j_settlement").addClass("weui-btn_disabled");
		} else {
			$(".j_total_num").show();
			$(".j_settlement").removeClass("weui-btn_disabled");
		}
	}
	$(".j_confirm").click(function(){
		$("#alertDialog").hide();
	});
	// submit
	$(".j_payment").click(function(){
		if (addrId == '') {
			$(".weui-dialog__bd").html("请选择收货人");
			$("#alertDialog").show();
		}
		
		var ogArr = new Array();
		$.each(goodsArr, function(i, val){      
			ogArr.push(val.id+","+val.count);
		});
		if (ogArr.length == 0) {
			$("#alertDialog").show();
		}
		return;
		
	});
});
</script>
</body>
</html>